/*
 * @Sergii Donchenko, Kiev 2012
 * Anagram
 * Program to find an Anagram
 */
 import java.util.*;
 public class Anagram
 {
	public static void main(String[] arg)
	{
		Scanner in = new Scanner (System.in);
		
		System.out.print ("Write first phrase:");
		String firstPhrase = in.nextLine();
		System.out.print ("Write second phrase:");
		String secondPhrase = in.nextLine();
		
		if (anagrams(firstPhrase, secondPhrase)) 
		{
			System.out.println ("Congratulations you win, its anagram!");
        } 
		else 
		{
			System.out.println ("So close..");
        }
	}
	
     public static char[] spaceKiller(String phrase) 
	{
       String phraseRedated = phrase.replaceAll("\\s","").toLowerCase();
       return phraseRedated.toCharArray();
    }

    public static boolean anagrams(String s1, String s2) // Thank you Google
	{
        char[] ch1 = spaceKiller(s1);
        char[] ch2 = spaceKiller(s2);
        Arrays.sort(ch1);
        Arrays.sort(ch2);
        return Arrays.equals(ch1,ch2);
    }
}